#************************************************************************
#*   IRC - Internet Relay Chat, src/Makefile
#*   Copyright (C) 1990 Jarkko Oikarinen
#*
#*   This program is free software; you can redistribute it and/or modify
#*   it under the terms of the GNU General Public License as published by
#*   the Free Software Foundation; either version 1, or (at your option)
#*   any later version.
#*
#*   This program is distributed in the hope that it will be useful,
#*   but WITHOUT ANY WARRANTY; without even the implied warranty of
#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#*   GNU General Public License for more details.
#*
#*   You should have received a copy of the GNU General Public License
#*   along with this program; if not, write to the Free Software
#*   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#*/

OBJS=bsd.o dbuf.o packet.o send.o match.o parse.o support.o channel.o \
	class.o hash.o ircd.o list.o res.o m_chgcmds.o m_sacmds.o m_svscmds.o \
	masking.o s_bsd.o s_conf.o s_debug.o s_err.o s_misc.o s_numeric.o \
	s_ping.o s_serv.o s_user.o s_zip.o whowas.o userload.o md5.o $(RES) $(STRTOUL)

SRC=$(OBJS:%.o=%.c)

MAKE = make 'CFLAGS=${CFLAGS}' 'CC=${CC}' 'IRCDLIBS=${IRCDLIBS}' \
	    'LDFLAGS=${LDFLAGS}' 'IRCDMODE=${IRCDMODE}'

MKDIR=mkdir
CHMOD=chmod
CHOWN=chown
CHGRP=chgrp
DPATH=../
IRCDMODE=0700
IRCDOWN=irc
IRCDGRP=irc
MPATH=../ircd.motd
INSTALL=../bsdinstall

MV=mv
GREP=grep
SHELL=/bin/sh
CC=__oops__

all: build

build: ircd chkconf

ircd: parenttest $(OBJS) 
	@${SHELL} version.c.SH
	${CC} ${CFLAGS} -c version.c;
	$(CC) $(CFLAGS) $(OBJS) version.o $(LDFLAGS) $(IRCDLIBS) -o ircd
	chmod $(IRCDMODE) ircd

parenttest:
	@if [ "${CC}" = "__oops__" ]; then \
		echo ""; echo ""; echo "";\
		echo "*** Run make from the parent directory ***"; \
		echo ""; echo "";echo "";\
		exit 1; \
	fi

chkconf: ../include/struct.h ../include/config.h  ../include/sys.h \
	 ../include/common.h chkconf.c
	$(CC) $(CFLAGS) -DCR_CHKCONF -o chkmatch.o -c match.c
	$(CC) $(CFLAGS) -o support.o -c support.c
	$(CC) $(CFLAGS) chkconf.c chkmatch.o support.o \
	$(LDFLAGS) $(IRCDLIBS) -o chkconf

clean:
	$(RM) -f *.o *~ *.sav *.save core ircd version.c chkconf

cleandir: clean

install: build
	@if [ ! -d ${DPATH} -a ! -f ${DPATH} ]; then \
	  echo "Creating directory ${DPATH}"; \
	  ${MKDIR} ${DPATH}; \
	  ${CHMOD} 700 ${DPATH}; \
	  ${CHOWN} ${IRCDOWN} ${DPATH}; \
	  ${CHGRP} ${IRCDGRP} ${DPATH}; \
	fi
	@echo "Installing new ircd as ${BINDIR}/ircd :"
	${INSTALL} -m ${IRCDMODE} -o ${IRCDOWN} -g ${IRCDGRP} ircd ${BINDIR}/ircd
	${INSTALL} -s -m 700 -o ${IRCDOWN} -g ${IRCDGRP} chkconf ${BINDIR}
	${INSTALL} -m 600 -o ${IRCDOWN} -g ${IRCDGRP} ../doc/example.conf ${DPATH}
	( cd ${DPATH}; \
	  ${TOUCH} ${MPATH}; \
	  ${CHOWN} ${IRCDOWN} ${MPATH}; \
	  ${CHGRP} ${IRCDGRP} ${MPATH}; )
	

depend: parenttest
	@if [ -f Makefile.bak ]; then \
	  echo "make depend: First remove src/Makefile.bak"; \
	else \
	  ( ${MV} Makefile Makefile.bak; \
	    ${GREP} -A1 -B1000 '^# DO NOT DELETE THIS LINE' Makefile.bak > Makefile;\
	    ${CC} ${CFLAGS} -MM ${SRC} >> Makefile; ) \
	fi

.SUFFIXES: .c .o

.c.o:
	${CC} ${CFLAGS} -c $< -o $@

# DO NOT DELETE THIS LINE -- make depend depends on it.

hash.o:	hash.c
bsd.o: bsd.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/h.h
dbuf.o: dbuf.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h
packet.o: packet.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/msg.h ../include/h.h
send.o: send.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/h.h
match.o: match.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h
parse.o: parse.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/msg.h ../include/numeric.h \
 ../include/h.h
support.o: support.c ../include/config.h ../include/setup.h \
  ../include/struct.h ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h
channel.o: channel.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/channel.h \
 ../include/msg.h ../include/hash.h ../include/h.h
class.o: class.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/h.h
hash.o: hash.c ../include/numeric.h ../include/struct.h \
 ../include/config.h ../include/setup.h  \
 ../include/common.h ../include/sys.h ../include/class.h \
 ../include/dbuf.h ../include/whowas.h ../include/hash.h \
 ../include/h.h
ircd.o: ircd.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/userload.h \
 ../include/h.h
list.o: list.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/h.h ../include/numeric.h
res.o: res.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/res.h ../include/numeric.h \
 ../include/h.h ../include/nameser.h ../include/resolv.h \
 ../include/inet.h
m_chgcmds.o: m_chgcmds.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/channel.h \
 ../include/msg.h ../include/hash.h ../include/h.h
m_sacmds.o: m_sacmds.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/channel.h \
 ../include/msg.h ../include/hash.h ../include/h.h
m_svscmds.o: m_svscmds.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/channel.h \
 ../include/msg.h ../include/hash.h ../include/h.h
masking.o: masking.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/msg.h \
 ../include/channel.h ../include/userload.h ../include/h.h
s_bsd.o: s_bsd.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/res.h ../include/numeric.h \
 ../include/patchlevel.h ../include/inet.h ../include/nameser.h \
 ../include/resolv.h ../include/sock.h ../include/h.h
s_conf.o: s_conf.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/channel.h \
 ../include/msg.h ../include/inet.h ../include/h.h
s_debug.o: s_debug.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/hash.h \
 ../include/h.h
s_err.o: s_err.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h
s_misc.o: s_misc.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/userload.h \
 ../include/h.h
s_numeric.o: s_numeric.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/h.h
s_ping.o: s_ping.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/patchlevel.h \
 ../include/sock.h ../include/h.h
s_serv.o: s_serv.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/msg.h \
 ../include/channel.h ../include/userload.h ../include/h.h
s_user.o: s_user.c ../include/config.h ../include/setup.h \
 ../include/struct.h ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/msg.h \
 ../include/channel.h ../include/userload.h ../include/h.h
s_zip.o: s_zip.c ../include/config.h ../include/setup.h \
 ../include/struct.h ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/msg.h \
 ../include/channel.h ../include/userload.h ../include/h.h
whowas.o: whowas.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/numeric.h ../include/h.h
userload.o: userload.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/userload.h ../include/h.h
md5.o: md5.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h
map.o: map.c ../include/struct.h ../include/config.h \
 ../include/setup.h  ../include/common.h \
 ../include/sys.h ../include/class.h ../include/dbuf.h \
 ../include/whowas.h ../include/h.h ../include/numeric.h
